//
//  LJTopicsModel.m
//  百思不得姐
//
//  Created by 刘鹿杰 on 16/8/22.
//  Copyright © 2016年 刘鹿杰. All rights reserved.
//

#import "LJTopicsModel.h"
#import <UIKit/UIKit.h>


@implementation LJTopicsModel


+(NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"big_image0":@"image0",
             @"big_image1":@"image1",
             @"middle_image2":@"image2",
             @"small_image3":@"image3"
             };
    
}

// 获取cell的高度
-(CGFloat)cellHight{
    
    if (!_cellHight) {
        // 计算文字的高度
        CGSize maxSize = CGSizeMake(KScreenW - 4 * LJTopicPictureMargin, CGFLOAT_MAX);
        
        CGFloat textH = [self.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil].size.height;
        
        _cellHight = LJTopicIconImageMaxY + textH  +  2 * LJTopicPictureMargin;
        
        if (self.type == LJTopicTypePicture) {
            
            CGFloat pictureY = _cellHight;
            CGFloat pictureW = maxSize.width;
            
            CGFloat pictureH = pictureW * self.height / self.width;
            
            if (pictureH > LJTopicCellPictureMaxH) {
                pictureH = LJTopicCellPictureBreakH;
                self.bigPicture = YES;
            }
            // 计算图片的frame
            _pictureFrame = CGRectMake(LJTopicPictureMargin, pictureY, pictureW, pictureH);
            _cellHight += pictureH + LJTopicPictureMargin;
            
        }
        _cellHight += LJTopicBottomHight + LJTopicPictureMargin;
    
    }
    return _cellHight;
}

@end
